var DATA_TYPE_PM25_IN = "pm25in";
var DATA_TYPE_PM25_OUT = "pm25out";
var DATA_TYPE_PM10 = "pm10";
var DATA_TYPE_JIAQUAN = "jiaquan";
var DATA_TYPE_WENDU1 = "wendu1";
var DATA_TYPE_WENDU2 = "wendu2";
var DATA_TYPE_WENDU3 = "wendu3";
var DATA_TYPE_WENDU4 = "wendu4";
var DATA_TYPE_SHIDU = "shidu";
var DATA_TYPE_TVOC = "tvoc";
var DATA_TYPE_CO2 = "co2";
var ValueSize = 14400;// x轴数据秒数
var chart1;
var bShowMsg = true;
var colorArr = [ '#0000ff', '#00aaff', '#000000', '#ff66ff', '#6666ff',
		'#006666' ];
var colorArr1 = [ '#0000ff', '#00aaff', '#000000', '#ff66ff', '#6666ff',
		'#006666' ];
var tickArr = [  0, 35, 75, 115, 150, 250, 500 , 800, 1000 ];
var excelName = "";
var waitTime = 0;
var msgArr = new Array();
var tmMap = new Object();
var NUM_POINTS = 30;// 曲线上显示的点数，必须大于(NUM_RECENT+1)
var NUM_RECENT = 10;
var histFrom = 0;
var histTo = 0;
var code = Math.floor(Math.random() * 65536);
var dataType = null;
var showType = '24h';// 24h,1h,hist
var pm25Bands = [ {
	color : 'rgba(0,255,0,0.8)',
	from : 0,
	to : 35
}, {
	color : '#FF0',
	from : 35,
	to : 75
}, {
	color : '#FF6100',
	from : 75,
	to : 115
}, {
	color : '#F00',
	from : 115,
	to : 150
// value:150,width:1
}, {
	color : '#E3170D',
	from : 150,
	to : 250
// value:250,width:1
}, {
	color : '#B22222',
	from : 250,
	to : 500
}, {
	color : '#B02020',
	from : 500,
	to : 800
}, {
	color : '#A51515',
	from : 800,
	to : 1000
} ];
var tPlotLines = [ {
	color : '#808080',
	value : -20,
	width : 1
}, {
	color : '#808080',
	value : 0,
	width : 1
}, {
	color : '#808080',
	value : 20,
	width : 1
}, {
	color : '#808080',
	value : 40,
	width : 1
}, {
	color : '#808080',
	value : 60,
	width : 1
} ];
var hPlotLines = [ {
	color : '#808080',
	value : 0,
	width : 1
}, {
	color : '#808080',
	value : 25,
	width : 1
}, {
	color : '#808080',
	value : 50,
	width : 1
}, {
	color : '#808080',
	value : 75,
	width : 1
}, {
	color : '#808080',
	value : 100,
	width : 1
} ];
function findTesters(uid, callback, deviceid) {
	if (uid) {
		if(!deviceid){
			deviceid = "";
		}
		$.ajax({
			type : 'post',
			url : base + '/getUserMachineInfo',
			data : {
				fun : 'findTesterListByUserId',
				userid : uid,
				deviceid : deviceid
			},
			success : function(r) {
				if (r.status == 'ok') {
					if (callback) {
						callback(r.result);
					}
				}
			}
		});
	}
}
var g_testers = {};
function showTesters(devs) {
	var str = "";
	for (var i = 0; i < devs.length; i++) {
		var devId = devs[i].id;
		// devId =
		// devId.substr(0,4).toUpperCase()+devId.substr(4,4).toUpperCase();
		var room = devs[i].devicename;
		var rt = devs[i].id;
		g_testers[devId] = {
			'name' : room,
			'rt' : rt
		};
		if (!rt) {
			rt = 63;
		}
		str += "<li class='list-group-item' title='设备号:" + devId + ",房间:"
				+ room + "' onclick='clk_tester(this)'>";
		if (devId == id) {
			selectDev(devId, room, rt);
			str += "<span class='check glyphicon glyphicon-check'></span> ";
		} else {
			str += "<span class='check glyphicon glyphicon-unchecked'></span> ";
		}
		str += "<span class='hide' data='sn'>" + devId + "</span>";
		str += "<input name='roomType' class=\"hide\" value=\"" + rt + "\"/>";
		str += "<a data='name' href=\"javascript:void(0)\">" + room + "</a>";
		str += "</li>";

	}
	$("#ul-tester").html(str);
}
function clk_checkTester(ip) {
	$(ip).prop('checked', !$(ip).prop('checked'));
	preventDefaultEvent(event);
	cancelBubbleEvent(event);
}
function strToDate(str) {
	var fullDate = str.split(" ")[0].split("-");
	var fullTime = str.split(" ")[1].split(":");
	return new Date(fullDate[0], fullDate[1] - 1, fullDate[2],
			(fullTime[0] != null ? fullTime[0] : 0),
			(fullTime[1] != null ? fullTime[1] : 0),
			(fullTime[2] != null ? fullTime[2] : 0));
}
function initHighchart() {
	Highcharts.setOptions({
		global : {
			useUTC : false
		// 关闭UTC
		},
		lang : {
			months : [ '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月',
					'10月', '11月', '12月' ],
			shortMonths : [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10',
					'11', '12' ],
			downloadXLS : '导出excel表格',
			downloadCSV : '导出Excel表格',
			downloadPNG : '导出PNG图片',
			downloadJPEG : '导出JPG图片',
			downloadPDF : '导出PDF图片',
			downloadSVG : '导出SVG图片',
			printChart : '打印',
			contextButtonTitle : '菜单'
		}
	});
	var options = {
		chart : {
			renderTo : 'chart',
			type : 'spline',
			margin : [ 50, 0, 120, 80 ],
			animation : false,
			zoomType : 'x',
			backgroundColor : 'rgba(0,0,0,0)'
		},
		legend : {
			y : -20
		},
		credits : {
			enabled : false,
			text : '数据来源: 激光PM2.5云测仪 SDM805',
			href : 'http://www.inovafitness.com',
			style : {
				cursor : 'pointer',
				color : '#808080',
				fontSize : '12px',
				fontFamily : 'microsoft yahei'
			},
			position : {
				align : 'right',
				x : -15,
				verticalAlign : 'top',
				y : 10
			}
		},
		/*
		 * exporting:{ buttons:{ contextButton:{ menuItems:[ {text:
		 * "导出CSV表格",onclick: function () {
		 * //Highcharts.post('/chart/exportCSV.action', {csv: this.getCSV()});
		 * Highcharts.post('/api/svc/csv.php', {csv: this.getCSV()}); }},
		 * {text:'导出Excel表格',onclick:function(){exportXls();}} ] }},
		 * enabled:true url:'http://export.hcharts.cn' },
		 */
		rangeSelector : {
			buttons : [ {
				type : 'month',
				count : 1,
				text : '1m'
			} ],
			enabled : true
		},
		title : {
			text : 'PM2.5实时数据' // 指定图表标题
		},
		xAxis : {
			type : 'datetime',
			dateTimeLabelFormats : {
				year : '%b-%e %H:%M',
				month : '%b-%e %H:%M',
				day : '%b-%e %H:%M',
				second : '%H:%M',
				millisecond : '%H:%M'
			},
			title : {
				text : '时间' // 指定x轴分组
			}
		},
		tooltip : {
			dateTimeLabelFormats : {
				year : '%Y-%b-%e %H:%M:%S',
				month : '%Y-%b-%e %H:%M:%S',
				day : '%Y-%b-%e %H:%M:%S',
				hour : '%Y-%b-%e %H:%M:%S',
				minute : '%Y-%b-%e %H:%M:%S',
				second : '%Y-%b-%e %H:%M:%S',
				millisecond : ''
			}
		},
		yAxis : [ {
			title : {
				text : 'PM2.5(ug/m3)' // 指定y轴的标题
			},
			labels : {
				format : '{value}'
			},
			plotBands : pm25Bands,
			gridLineWidth : 0,
			min : null/*,
			tickPositions : [ 0, 35, 75, 115, 150, 250,1000 ]*/
		} ],
		series : []
	};
	chart1 = new Highcharts.Chart(options);
	chart1.setSize($("#chart").width(), $(window).height() - 115, true);
	$(window).resize(function() {
		if($(window).height() - 115 > 500){
			chart1.setSize($("#chart").width(), $(window).height() - 115, true);
		}else{
			chart1.setSize($("#chart").width(), 300, true);
		}
	});
}
function chngDataType(newType) {
	if (newType == dataType) {
		return false;
	}
	dataType = newType;
	if (dataType == DATA_TYPE_WENDU1 || dataType == DATA_TYPE_WENDU2 || dataType == DATA_TYPE_WENDU3 || dataType == DATA_TYPE_WENDU4) {
		if(dataType == DATA_TYPE_WENDU1){
			chart1.setTitle({
				text : '室内进风温度数据' // 指定图表标题
			});
		}else if(dataType == DATA_TYPE_WENDU2){
			chart1.setTitle({
				text : '室内出风温度数据' // 指定图表标题
			});
		}else if(dataType == DATA_TYPE_WENDU3){
			chart1.setTitle({
				text : '室外进风温度数据' // 指定图表标题
			});
		}else if(dataType == DATA_TYPE_WENDU4){
			chart1.setTitle({
				text : '室外出风温度数据' // 指定图表标题
			});
		}else {
			chart1.setTitle({
				text : '温度数据' // 指定图表标题
			});
		}
		chart1.yAxis[0].update({
			title : {
				text : '温度(°C)'
			},
			min : null,
			labels : {
				format : '{value}'
			},
			gridLineWidth : 1,
			plotBands : null,
			tickPositions : null
		}, false, true);
	} else if (dataType == DATA_TYPE_SHIDU) {
		chart1.setTitle({
			text : '湿度数据' // 指定图表标题
		});
		chart1.yAxis[0].update({
			title : {
				text : '湿度(%)'
			},
			min : null,
			labels : {
				format : '{value}'
			},
			gridLineWidth : 1,
			opposite : false,
			plotBands : null,
			tickPositions : null
		}, false, true);
	} else if (dataType == DATA_TYPE_CO2) {
		chart1.setTitle({
			text : 'CO2数据' // 指定图表标题
		});
		chart1.yAxis[0].update({
			title : {
				text : 'CO2(ppm)'
			},
			min : null,
			labels : {
				format : '{value}'
			},
			gridLineWidth : 1,
			opposite : false,
			plotBands : null,
			tickPositions : null
		}, false, true);
	} else if (dataType == DATA_TYPE_JIAQUAN) {
		chart1.setTitle({
			text : '甲醛数据' // 指定图表标题
		});
		chart1.yAxis[0].update({
			title : {
				text : '甲醛指数(mg/m3)'
			},
			min : null,
			labels : {
				format : '{value}'
			},
			gridLineWidth : 1,
			opposite : false,
			plotBands : null,
			tickPositions : null
		}, false, true);
	} else if (dataType == DATA_TYPE_PM25_IN || dataType == DATA_TYPE_PM25_OUT) {
		if(dataType == DATA_TYPE_PM25_IN){
			chart1.setTitle({
				text : '室内PM2.5数据' // 指定图表标题
			});
		}else if(dataType == DATA_TYPE_PM25_OUT){
			chart1.setTitle({
				text : '室外PM2.5数据' // 指定图表标题
			});
		}else{
			chart1.setTitle({
				text : 'PM2.5数据' // 指定图表标题
			});
		}
		
		chart1.yAxis[0].update({
			title : {
				text : 'PM2.5(ug/m3)'
			},
			min : null,
			labels : {
				format : '{value}'
			},
			plotBands : pm25Bands,
			gridLineWidth : 0,
			opposite : false/*,
			tickPositions : [  0, 35, 75, 115, 150, 250 ,1000 ]*/
		}, false, true);
	} else if (dataType == DATA_TYPE_PM10) {
		chart1.setTitle({
			text : 'PM10官方数据' // 指定图表标题
		});
		chart1.yAxis[0].update({
			title : {
				text : 'PM10(ug/m3)'
			},
			min : null,
			labels : {
				format : '{value}'
			},
			plotBands : pm25Bands,
			gridLineWidth : 0,
			opposite : false/*,
			tickPositions : [  0, 35, 75, 115, 150, 250,1000  ]*/
		}, false, true);
	}
	// reloadData();
	return true;
}
function loadHoursDataOfAll(hour) {
	var submittype = dataType;
	if(dataType == DATA_TYPE_PM25_OUT){
		submittype = DATA_TYPE_PM25_IN;
	}else if (dataType == DATA_TYPE_PM25_IN){
		submittype = DATA_TYPE_PM25_OUT;
	}
	var devs = getDevs();
	var type = dataType;
	$.ajax({
		type : 'post',
		url : getDataUrl,
		data : {
			fun : 'getmyhourData',
			type : submittype,
			hour : hour,
			sn : devs
		},
		success : function(r) {
			if (type == dataType) {
				appendData(r);
			}
		}
	});
}
function loadHoursDataOfDev(sn, hour) {
	var submittype = dataType;
	if(dataType == DATA_TYPE_PM25_OUT){
		submittype = DATA_TYPE_PM25_IN;
	}else if (dataType == DATA_TYPE_PM25_IN){
		submittype = DATA_TYPE_PM25_OUT;
	}
	var type = dataType;
	$.ajax({
		type : 'post',
		url : getDataUrl,
		data : {
			fun : 'get' + hour + 'hData',
			type : submittype,
			sn : sn
		},
		success : function(r) {
			if (type == dataType) {
				appendData(r);
			}
		}
	});
}
function load1hDataOfAll() {
	var devs = getDevs();
	var submittype = dataType;
	if(dataType == DATA_TYPE_PM25_OUT){
		submittype = DATA_TYPE_PM25_IN;
	}else if (dataType == DATA_TYPE_PM25_IN){
		submittype = DATA_TYPE_PM25_OUT;
	}
	var type = dataType;
	$.ajax({
		type : 'post',
		url : getDataUrl,
		data : {
			fun : 'get1hData',
			type : submittype,
			sn : devs
		},
		success : function(r) {
			if (type == dataType) {
				appendData(r);
			}
		}
	});
}
function load1hDataOfDev(devId) {
	
	var submittype = dataType;
	if(dataType == DATA_TYPE_PM25_OUT){
		submittype = DATA_TYPE_PM25_IN;
	}else if (dataType == DATA_TYPE_PM25_IN){
		submittype = DATA_TYPE_PM25_OUT;
	}
	var type = dataType;
	if (devId && devId.length > 0) {
		// devId = devId.replace('-','');
		$.ajax({
			type : 'post',
			url : getDataUrl,
			data : {
				fun : 'get1hData',
				type : submittype,
				sn : devId
			},
			success : function(r) {
				if (type == dataType) {
					appendData(r);
				}
			}
		});
	}
}
function load24hDataOfAll() {
	
	var submittype = dataType;
	if(dataType == DATA_TYPE_PM25_OUT){
		submittype = DATA_TYPE_PM25_IN;
	}else if (dataType == DATA_TYPE_PM25_IN){
		submittype = DATA_TYPE_PM25_OUT;
	}
	var devs = getDevs();
	var type = dataType;
	$.ajax({
		type : 'post',
		url : getDataUrl,
		data : {
			fun : 'get24hData',
			type : submittype,
			sn : devs
		},
		success : function(r) {
			if (type == dataType) {
				appendData(r);
			}
		}
	});
}
function loadDataOfAll() {
	if (showType == '24h') {
		load24hDataOfAll();
	} else if (showType == '1h') {
		load1hDataOfAll();
	} else if (showType == 'hist') {
		loadHistDataOfAll();
	}
}
function loadDataOfDev(devId) {
	if (showType == '24h') {
		load24hDataOfDev(devId);
	} else if (showType == '1h') {
		load1hDataOfDev(devId);
	} else if (showType == 'hist') {
		loadHistDataOfDev(devId);
	}
}
function load24hDataOfDev(devId) {
	var submittype = dataType;
	if(dataType == DATA_TYPE_PM25_OUT){
		submittype = DATA_TYPE_PM25_IN;
	}else if (dataType == DATA_TYPE_PM25_IN){
		submittype = DATA_TYPE_PM25_OUT;
	}
	var type = dataType;
	if (devId && devId.length > 0) {
		// devId = devId.replace('-','');
		$.ajax({
			type : 'post',
			url : getDataUrl,
			data : {
				fun : 'get24hData',
				type : submittype,
				sn : devId
			},
			success : function(r) {
				if (type == dataType) {
					appendData(r);
				}
			}
		});
	}
}
function appendData(data) {
	if (data.status != 'ok' || data.result.length == 0) {
		return;
	} else {
		var addhtml = "";
		if(!isclickli){
			$("#showdatainfo").html("");
		}else{
			addhtml = $("#showdatainfo").html();
		}
		if (dataType != DATA_TYPE_PM25_IN && dataType != DATA_TYPE_PM25_OUT) {
			chart1.yAxis[0].update({
				min : null
			}, false);
		}
		var id = "";
		for (var i = 0; i < data.result.length; i++) {
			var d = data.result[i];
			var sn = d.id;
			if(id != sn){
				if(data.result[i].devicename){
					$("#showdatainfo").append("<tr name='"+data.result[i].id+"'><td colspan=2 nowrap style='text-align:center;font:bold;color:green;'>---"  + data.result[i].devicename + "---</td></tr>");
				}
				id = sn;
			}
			var se = chart1.get(sn);
			if (!se) {
				continue;
			}
//			var rt = g_testers[sn]['rt'];
//			if (!rt) {
//				rt = 63;
//			}
//			var rtpm25 = parseInt(rt) & 1;
//			var rtwd = parseInt(rt) & (1 << 1);
//			var rtsd = parseInt(rt) & (1 << 2);
//			var rtco2 = parseInt(rt) & (1 << 3);
//			var rttvoc = parseInt(rt) & (1 << 4);
//			var rtjq = parseInt(rt) & (1 << 5);
//			if (rtpm25 == 0 && dataType == DATA_TYPE_PM25) {
//				continue;
//			} else if (rtwd == 0 && dataType == DATA_TYPE_WENDU) {
//				continue;
//			} else if (rtsd == 0 && dataType == DATA_TYPE_SHIDU) {
//				continue;
//			} else if (rtjq == 0 && dataType == DATA_TYPE_JIAQUAN) {
//				continue;
//			} else if (rttvoc == 0 && dataType == DATA_TYPE_TVOC) {
//				continue;
//			} else if (rtco2 == 0 && dataType == DATA_TYPE_CO2) {
//				continue;
//			}

			var date = strToDate(d.recievedate);
			var t = date.getTime();
			var v = parseFloat(d.pm25in);
			
			if (dataType == DATA_TYPE_PM25_OUT) {
				v = parseFloat(d.pm25in);
			} else if (dataType == DATA_TYPE_PM25_IN) {
				v = parseFloat(d.pm25out);
			} else if (dataType == DATA_TYPE_WENDU1) {
				v = parseFloat(d.enteringairtempin);
			} else if (dataType == DATA_TYPE_WENDU2) {
				v = parseFloat(d.leavingairtempin);
			} else if (dataType == DATA_TYPE_WENDU3) {
				v = parseFloat(d.enteringairtempout);
			} else if (dataType == DATA_TYPE_WENDU4) {
				v = parseFloat(d.leavingairtempout);
			} else if (dataType == DATA_TYPE_SHIDU) {
				v = parseFloat(d.humidity);
			} else if (dataType == DATA_TYPE_JIAQUAN) {
				v = parseFloat(d.formaldehyde);
			} else if (dataType == DATA_TYPE_TVOC) {
				v = parseFloat(d.pm25in);
			} else if (dataType == DATA_TYPE_CO2) {
				v = parseFloat(d.co2);
			}
			
			
			if (dataType == DATA_TYPE_WENDU1 ||dataType == DATA_TYPE_WENDU2 ||dataType == DATA_TYPE_WENDU3 ||dataType == DATA_TYPE_WENDU4 || dataType == DATA_TYPE_SHIDU) {
				v = parseFloat(v.toFixed(2));
			} else if (dataType == DATA_TYPE_TVOC) {
				v = parseFloat(v.toFixed(3));
			} else {
				v = Math.round(v * 10) / 10;
			}
			if (dataType == DATA_TYPE_TVOC && v < 0) {
				v = -v;
			}
			se.addPoint({
				x : t,
				y : v
			}, true, false);
			
			var htmlstr = "<tr name='"+data.result[i].id+"'><td nowrap style='text-align:left;'>"  + d.recievedate + "</td><td nowrap style='text-align:right;'>" + v + "</td></tr>";
			$("#showdatainfo").append(htmlstr);
			
		}
		//$("#showdatainfo").append(addhtml);
		
		isclickli = false;
		if (dataType != DATA_TYPE_PM25_IN && dataType != DATA_TYPE_PM25_OUT) {
			if (dataType != DATA_TYPE_WENDU1 && dataType != DATA_TYPE_WENDU2
					&& dataType != DATA_TYPE_WENDU3&& dataType != DATA_TYPE_WENDU4) {// 不可能是负值
				if (chart1.yAxis[0].min < 0) {
					chart1.yAxis[0].update({
						min : 0
					}, true);
				}
			}
		}
		tickArr = chart1.yAxis[0].tickPositions.slice(0);
	}
}
function loadHistDataOfAll() {
	var submittype = dataType;
	if(dataType == DATA_TYPE_PM25_OUT){
		submittype = DATA_TYPE_PM25_IN;
	}else if (dataType == DATA_TYPE_PM25_IN){
		submittype = DATA_TYPE_PM25_OUT;
	}
	var devs = getDevs();
	var from = $("#startDate").val();
	var to = $("#endDate").val();
	if (from == '' || to == '') {
		alert('请输入起止时间');
		return;
	}
	var type = dataType;
	$.ajax({
		type : 'post',
		url : getDataUrl,
		data : {
			fun : 'getHistData',
			sn : devs,
			type : submittype,
			from : from,
			to : to
		},
		success : function(r) {
			if (type == dataType) {
				appendData(r);
			}
		}
	});
}
function loadHistDataOfDev(sn) {
	var submittype = dataType;
	if(dataType == DATA_TYPE_PM25_OUT){
		submittype = DATA_TYPE_PM25_IN;
	}else if (dataType == DATA_TYPE_PM25_IN){
		submittype = DATA_TYPE_PM25_OUT;
	}
	var from = $("#startDate").val();
	var to = $("#endDate").val();
	if (from == '' || to == '') {
		alert('请输入起止时间');
		return;
	}
	var type = dataType;
	$.ajax({
		type : 'post',
		url : getDataUrl,
		data : {
			fun : 'getHistData',
			sn : sn,
			type : submittype,
			from : from,
			to : to
		},
		success : function(r) {
			if (type == dataType) {
				appendData(r);
			}
		}
	});
}
function getDevs() {
	var devs = "";
	for (var i = 0; i < chart1.series.length; i++) {
		if (i > 0) {
			devs += ',';
		}
		devs += chart1.series[i].options.id;
	}
	return devs;
}
var isclickli = false;
function clk_tester(li) {
	var sn = $(li).find("span[data='sn']").text();
	var roomType = $(li).find("input[name='roomType']").val();
	var room = $(li).find("a[data='name']").text();
	var cb = $(li).find("span.check");
	isclickli = true;
	if ($(cb).hasClass('glyphicon-check')) {
		// $(cb).prop('checked',false);
		$(cb).removeClass('glyphicon-check');
		$(cb).addClass('glyphicon-unchecked');
		unselectDev(sn, room);
	} else {
		/*
		 * if (chart1.series.length>=6) { alert("最多只能选择6个设备"); return; }else{
		 */
		// $(cb).prop('checked',true);
		$(cb).removeClass('glyphicon-unchecked');
		$(cb).addClass('glyphicon-check');
		selectDev(sn, room, roomType);
		loadDataOfDev(sn);
		// }
	}
}
function getRandomColor() {
	var numbers = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
			'C', 'D', 'E', 'F' ];
	var ret = "#";
	for (var i = 0; i < 6; i++) {
		ret += numbers[Math.floor(Math.random() * 16)];
	}
	return ret;
}
function selectDev(devId, room, roomType) {

	if (chart1.series) {

		// 是否已添加过
		for (var i = chart1.series.length - 1; i >= 0; i--) {
			if (chart1.series[i].name == room) {
				return;
			}
		}
	}
	tmMap[devId] = 0;
	var color = colorArr.pop();
	if (!color) {
		color = getRandomColor();
	}
	chart1.addSeries({
		id : devId,
		name : room,
		data : [],
		marker : {
			radius : 3
		},
		color : color
	}, true, false);
}
function unselectDev(devId, room) {
	delete tmMap[devId];
	colorArr.push(chart1.get(devId).color);
	chart1.get(devId).remove();
	
	$("tr[name='" +devId + "']").remove();
	
}
function clearSeries() {
	for (var i = 0; i < chart1.series.length; i++) {
		chart1.series[i].setData([]);
	}
}
function click_historyData(btn) {
	$("div.hist").show();
	showType = 'hist';
}
function click_showHist() {
	if ($("#startDate").val() == "" || $("#endDate").val() == "") {
		return;
	} else {
		reloadData();
	}
	// showTip("正在加载历史数据,请稍后...");
}
function click_1hData(btn) {
	if (showType == '1h') {
		return;
	} else {
		$("div.hist").hide();
		showType = '1h';
		reloadData();
	}
}
function click_currentData(btn) {
	if (showType == '24h') {
		return;
	} else {
		$("div.hist").hide();
		showType = '24h';
		reloadData();
	}
}
function reloadData() {
	clearSeries();
	loadDataOfAll();
}
function click_type(btn) {
	var type = $(btn).val();
	if (!chngDataType(type)) {
		return;
	}
	reloadData();
}
function clk_zoomOut() {
	var a = chart1.yAxis[0].tickPositions;
	if (a.length > 2) {
		a.pop();
		chart1.yAxis[0].update({
			tickPositions : a
		}, true);
	}
}
function clk_zoomIn() {
	var a = chart1.yAxis[0].tickPositions;
	if (a.length < tickArr.length) {
		a.push(tickArr[a.length]);
	} else {
		a.push(a[a.length - 1] * 1.5);
	}
	chart1.yAxis[0].update({
		tickPositions : a
	}, true);
}
function showTip(tip) {
	$("#tipBox").text(tip);
	$("#tipBox").css("display", "block");
	setTimeout(function() {
		$("#tipBox").text("");
		$("#tipBox").css("display", "none");
	}, 5000);
}
function getDataTypeName(type) {
	if (type == DATA_TYPE_PM25_IN) {
		return "室内PM2.5";
	} else if (type == DATA_TYPE_PM25_OUT) {
		return "室外PM2.5";
	} else if (type == DATA_TYPE_CO2) {
		return "CO2";
	} else if (type == DATA_TYPE_TVOC) {
		return "TVOC";
	} else if (type == DATA_TYPE_WENDU1) {
		return "室内进风温度";
	} else if (type == DATA_TYPE_WENDU2) {
		return "室内出风温度";
	} else if (type == DATA_TYPE_WENDU3) {
		return "室外进风温度";
	} else if (type == DATA_TYPE_WENDU4) {
		return "室外出风温度";
	} else if (type == DATA_TYPE_SHIDU) {
		return "湿度";
	} else if (type == DATA_TYPE_JIAQUAN) {
		return "甲醛";
	} else {
		return "选择类型";
	}
}